<?php
error_reporting(0);
include_once '../comm/config.php';
include_once '../comm/Taoapi.php';
include_once '../comm/wjt.php';
include_once '../comm/checkpostandget.php';

function json_to_array($web) {
	$arr = array ();
	foreach ($web as $k => $w) {
		if (is_object($w))
			$arr[$k] = json_to_array($w); //判断类型是不是object
		else
			$arr[$k] = $w;
	}
	return $arr;
}

function js_set($commission,$num_iid){
    echo "$('span[fanli=back_".$num_iid."]').html('".$commission."').attr('class','recome leiji');";
}

function DeleteHtml($str) {
	$str = trim($str);
	//$str = strip_tags($str,"");
	$str = ereg_replace("\t", "", $str);
	$str = ereg_replace("\r\n", "", $str);
	$str = ereg_replace("\r", "", $str);
	$str = ereg_replace("\n", "", $str);
	$str = preg_replace("|\s|", "", $str);
	return trim($str);
}

$uid=trim($_GET['u']);
if(!empty($uid)){
	$Taoapi_Config = Taoapi_Config::Init();
	$Taoapi_Config->setCharset('UTF-8');
	$Taoapi = new Taoapi;
	$Taoapi->method = 'taobao.user.get';
    $Taoapi->fields = 'user_id,buyer_credit';
	$Taoapi->nick = $uid;
	$TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
	$Result_users = $TaoapiUsers["user"];
	$sid=$Result_users["user_id"];
	$level=$Result_users['buyer_credit']['level'];
	
    $url = "http://rate.taobao.com/member_rate.htm?userId=".$sid."&identity=1&direction=0&rater=1";
    $s = DeleteHtml(file_get_contents($url));
    $s = str_replace('TB.rateList=', '', $s);
    $s = trim(iconv("gbk", "utf-8//IGNORE",$s));
    $web = json_decode($s);
    $arr = json_to_array($web);
}
$baobei_num=$arr['rateList']['paginator']['items'];
$tag="cha";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>检测,看看<?=WEBNICK?>能为你在淘宝网购物节省多少钱,很准噢</title>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META content=IE=EmulateIE7 http-equiv=X-UA-Compatible>
<LINK rel=stylesheet type=text/css href="../template/<?=MOBAN?>/css/common.css">
<link type="text/css" rel="stylesheet" href="images/style.css" />
<script type="text/javascript" language="javascript" src="../js/jquery.js"></script>
<script>
function chkTaoUser(obj) {
	if (obj.value=='输入您的淘宝帐号看下能省多少钱？' || obj.value=='') {
		obj.value = '';
		obj.focus();
		return false;
	}
	return true;
}
</script>
<style type="text/css">
<!--
.STYLE1 {color: #0000FF}
.STYLE2 {color: #333333}
body,td,th {
	color: #333333;
}
a {
	font-size: 12px;
	color: #333333;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #333333;
}
a:hover {
	text-decoration: underline;
	color: #333333;
}
a:active {
	text-decoration: none;
	color: #990000;
}
.recome{ color:#F00}
-->
</style>
</head><body>
 <?php include('../template/'.MOBAN.'/header.tpl.php')?>
 <?php include('../template/'.MOBAN.'/nav.tpl.php')?>
<div class="wrapper">
  <?php if(empty($uid)){?>
<form action="" method="get" onSubmit="return chkTaoUser(this.u);">
<div class="banner">
<div class="text">
<input name="u" type="text" class="name" id="u" value="输入您的淘宝帐号看看能省多少钱？" onFocus="this.value='';chkTaoUser(this)" />
<input type="submit" value=" " class="smt" /></div><div class="why" id="about"><em onClick="$('#about').hide('slow')"></em>温馨提示：<?=WEBNICK?>是淘宝特约合作网站，<br />返现金额实际上是淘宝商家支付的广告费，<br />
本站将所得广告费全部返还给会员！</div></div>
</form>
<?php }else{?>
<div class="detal">
<div class="contain"><a href="?u=" style="float:right"><img src="images/back_smt.gif" border="0" /></a><span>淘宝帐号:</span><span><?=$uid?></span>   </span><span> 买家信用:</span><a href="http://rate.taobao.com/user-rate-<?=$sid?>--receivedOrPosted%7C0--buyerOrSeller%7C1.htm#RateType" target="_blank"><img src="images/sell_level/<?=$level?>.gif" height="16" border="0" /></a><br />
<span>您从 [<span id="stoptime"></span>]到 [<span id="starttime"></span>] 期间</span><br />
<span>淘宝花费：</span><span class="red" id="totPrice">￥--.--</span><span>如经过本站购买可返现约:</span><span class="red" id="backPrice">￥-.--</span></div>
<div class="notice">以上所计算的是您在淘宝购买的部分宝贝后所能获得的大概返现！</div>
<div class="remmend"><span>　</span><a href="<?=$siteurl?>" target="_blank">三步轻松拿返现</a>　<a href="javascript:;" onClick="alert('查询到的记录只是您购买成功的且已经给卖家评价的宝贝记录！还有部分没有评价的宝贝没有显示出来但很多都有返现！\n')">为什么我少了一些购买记录？</a>&nbsp;&nbsp;&nbsp;<a href="/" target="_blank">去购物拿返现＞＞</a></div>

<div class="why" id="about"><em onClick="$('#about').hide('slow')"></em>温馨提示：<?=WEBNICK?>是淘宝特约合作网站，<br />
返现金额实际上是淘宝商家支付的广告费，<br />
本站将所得广告费拿出大部份返还给会员！</div></div>
<?php }?>
<div class="main">
<div class="left"></div>
<div class="bg" style=" height:auto">

<div class="title" style=" height:auto">
<table width="95%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><span class="user_name"><em>宝贝名称 / 时间</em></span></td>
    <td align="center"><span class="host">掌  柜</span></td> 
    <td><span class="prise">购买价格</span></td>
    <td><span class="recome">返现 </span></td>
  </tr>
</table>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<?php $n=1;?>
  <?php foreach($arr['rateList']['rateListDetail'] as $row){$row=json_to_array($row);?>
  <?php if($n==1){$ebuytime=$row['rateDate'];}?>
  <tr>
    <td><span class="user_name"><a href="../list.php?q=<?=urlencode($row['auctionTitle'])?>" target="_blank"><?=$row['auctionTitle']?></a><br /><em><?=substr($row['rateDate'],0,10)?></em></span></td>
    <td><div align="center"><span class="host"><a href="../shop.php?nick=<?=urlencode($row['displayUserNick'])?>" target="_blank"><?=$row['displayUserNick']?></a><br /><img src="http://pics.taobaocdn.com/newrank/<?=$row['displayRatePic']?>" /></span></div></td> 
    <td align="center"><div><span class="prise">￥<?=$row['auctionPrice']?></span></div></td>
    <td><div align="center"><span class="recome nofanli" fanli="back_<?=$row['auctionNumId']?>">获取中...</span></div></td>
  </tr>
  <?php 
  $niids.=$row['auctionNumId'].','; 
  $huafei+=$row['auctionPrice']; 
  $n++;
  $niid_arr[]=$row['auctionNumId'];
  }
  ?>
</table>

<div style="clear:both"></div>
</div>
<?php if(empty($uid)){?>
<div style="text-align:center; font-size:14px; line-height:50px;"><p align="left" style="color:red;font-weight:bold">
输入您的淘宝账号，就可以为您查询出您最近购买的宝贝记录，并为您计算出这些商品通过<?=WEBNICK?>购买后所获得的返现<br />
<span class="STYLE1">如查询不到，可刷新下重新查询即可！</span><br />
<span class="STYLE2" style=" text-indent:2em;text-align:left;">也许你还不知道什么是淘宝网购物返现，也许你也不相信在淘宝网购物真的能返现，不过，淘宝返现检测工具能为你检测出你最近购买的淘宝商品，并计算出理论应返现多少金额。如果你通过返现网或者使用淘宝一键返现宝购买这些商品，那就能得到相应的淘宝购物返现金额，最高能返现相应商品的50%哦~~~</span></p></div> 
<?php }elseif($sid==0){?>
<div style="text-align:center; font-size:14px; line-height:50px;">Sorry!你输入的淘宝账号有误，请核实后在查询！谢谢</div> 
<?php }else{?>	
<div class="total">
  <div class="smt_reg"><input type="submit" class="reg" value=" " onClick="location.href='../user/register.php'" /></div>
  <span>淘宝帐号:</span><span><?=$uid?></span>    
  <span> 买家信用:</span><a href="http://rate.taobao.com/user-rate-<?=$sid?>--receivedOrPosted%7C0--buyerOrSeller%7C1.htm#RateType" target="_blank"><img src="images/sell_level/<?=$level?>.gif" height="16" border="0" /></a><br />
  <span>您在淘宝花费：</span><span class="red" id="totPrice1">￥0</span> <span>通过本站购买可返现超过:</span><span class="red" id="backPrice1">￥-.--</span>
</div>
<?php }?>
</div>
<div class="right"></div>
<div style="clear:both"></div>

</div></div>
<script>
<?php
$niid_row=array();
$mm=0;
foreach($niid_arr as $v){
    if($mm<20){
	    $niid_row[0][]=$v;
	}
	elseif($mm<40){
	    $niid_row[1][]=$v;
	}
	elseif($mm<60){
	    $niid_row[2][]=$v;
	}
	elseif($mm<80){
	    $niid_row[3][]=$v;
	}
	elseif($mm<100){
	    $niid_row[4][]=$v;
	}
	$mm++;
}

foreach($niid_row as $aa){
	$niids=implode(',',$aa);
    $Taoapi->method = 'taobao.taobaoke.items.convert';
    $Taoapi->fields = 'commission,num_iid';
    $Taoapi->nick = MYUSERNICK;
    $Taoapi->num_iids = $niids;
    $comm_TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
    $comm_TaobaokeItem = $comm_TaobaokeData["taobaoke_items"]["taobaoke_item"];
	if($baobei_num==1){
	    $comm_TaobaokeItem[0]=$comm_TaobaokeItem;
	}
    foreach($comm_TaobaokeItem as $bb){
        $commission=round($bb['commission']*FXBL,2);
	    $num_iid=$bb['num_iid'];
	    js_set($commission,$num_iid);
	    $totcommission+=$commission;
    }
}
?>
var leiji=0;
$('#stoptime').html('<?=substr($row['rateDate'],0,10)?>');
$('#starttime').html('<?=substr($ebuytime,0,10)?>');
$('#totPrice').html('￥'+'<?=$huafei?>');
$('#totPrice1').html('￥'+'<?=$huafei?>');

$('.nofanli').html('0');
$('.leiji').each(function(){
    leiji+=parseFloat($(this).html());
});
leiji=leiji.toFixed(2);
$('#backPrice').html('￥'+leiji);
$('#backPrice1').html('￥'+leiji);
</script>
<DIV class=clear></DIV>
<?php include('../template/'.MOBAN.'/footer.tpl.php')?></body></html>